<?php
class Common
{
    /**
     * Debug
     * @author Tucq
     */
    public static function debug($var) {
        echo '<pre style="text-align: left;font-size: 14;">';
        $trace = debug_backtrace();
        echo 'Line: '.$trace[0]['line'].'<br>';
        print_r($var);
        echo '</pre>';
    }

    /**
     * Debug then die
     * @author Tucq
     */
    public static function debugdie($var) {
        echo '<pre style="text-align: left;font-size: 14;">';
        $trace = debug_backtrace();
        echo 'Line: '.$trace[0]['line'].'<br>';
        print_r($var);
        echo '</pre>';
        die();
    }

    public static function log($message = null, $filename = ''){
        if(is_null($message) and !$message)
            return;

        $filename .= date('Y-m-d');
        $logDir = dirname(__FILE__).'/log';
        if (!is_dir($logDir)) {
            mkdir($logDir, 0777);
        }
        $fp = fopen($logDir . '/' . $filename . '.log', 'a');
        if ($fp) {
            fwrite($fp, sprintf("%s %s\n", date('H:i:s'), print_r($message, true)));
            fclose($fp);
        }
    }
}